<?php
namespace jy_merch;
defined('BY_JYA') or exit('error');
/*
*/
class notice extends \plugin{
	public function gettpl_data($orderid,$type=0){//type=0表单订单，type=1
		return false;
	}
	public function sendcoupon($mid=0){
		$setting=$this->setting;
		$msg=array( 
			'first' => array('value' => $setting['frist'], 'color' => $setting['fristcolor']),
			'keyword1' => array('value' => $setting['keyword1'], 'color' => $setting['keyword1color']),
			'keyword2' => array('value' => $setting['keyword2'], 'color' => $setting['keyword2color']), 
			'remark' => array('value' => $setting['remark'], 'color' => $setting['remarkcolor']),
		);
		$url=custom_url('jy_weishop/coupon.myindex/',true);
		if(!$setting['templateid']){
			exi('请通知管理员设置模板消息ID！','error');
		}
		if($setting['templateid'] && $mid){
			cfc('account')->sendTplNotice($mid, $setting['templateid'], $msg, $url, $topcolor = '#FF683F');
		}
		return false;
	}
	public function sendmsg($mid=0,$content=''){
		$setting=$this->setting;
		$msg=array( 
			'first' => array('value' => $setting['msgfrist'], 'color' => $setting['msgfristcolor']),
			'keyword1' => array('value' => $content, 'color' => $setting['msgkeyword1color']),
			'keyword2' => array('value' => $setting['msgkeyword2'], 'color' => $setting['msgkeyword2color']), 
			'remark' => array('value' => $setting['msgremark'], 'color' => $setting['msgremarkcolor']),
		);
		$url=custom_url('jy_merch/member.index/',true);
		if(!$setting['msgtemplateid']){
			exi('请通知管理员设置模板消息ID！','error');
		}
		if($setting['msgtemplateid'] && $mid){
			cfc('account')->sendTplNotice($mid, $setting['msgtemplateid'], $msg, $url, $topcolor = '#FF683F');
		}
		return false;
	}
	public function notice_fenxiao_dakuan($mid,$fee=0){
		//打款通知
		$template_id=cfc('account')->check_tpl_template('OPENTM400492077','jy_merch','打款通知');
		$userinfo=pdo_get('core_members',array('id'=>$mid),array('fromuser','nickname'));
		$message=array(
			'first'=>array('value'=>'您好,提现申请已打款成功！',"color" => "#4a5077"),
			'keyword1'=>array('title'=>'用户ID','value'=>$userinfo['nickname'],"color" => "#4a5077"),			
			'keyword3'=>array('title'=>'打款金额','value'=>$fee,"color" => "#4a5077"),
			'keyword2'=>array('title'=>'打款时间','value'=>date('Y/m/d H:i:s',time()),"color" => "#4a5077"),
			'remark'=>array('value'=>'感谢您的使用！！',"color" => "#4a5077"),
		);
		if(!$url){
			$url=custom_url('jy_merch/member.index/',true);
		}
		cfc('account')->sendtwoNotice($mid,$template_id,$message,$url,'fenxiao_dakuan','jy_merch');
	}
	public function notice_diancan($order=array()){
		//点餐成功通知
		$wxapp_id=$order['wxapp_id'];
		if(!$_SESSION['wxapp_id'] && !$wxapp_id){
			$wxapp_id=cfc('fans')->get_appid($order['mid'],1);
		}
		if($_SESSION['wxapp_id'] || $wxapp_id){
			$wxapptemplate_id=cfc('wxapp_api')->get_tpl_template_id('1818',[6,10,11,5,2],'pay2buyer','点餐成功通知','jy_merch');
		}
		if($order['merchid']){
			$order['storetitle']=pdo_getcolumn('jy_merch_user',array('id'=>$order['merchid'],'uniacid'=>$_SESSION['uniacid']),'merchname');
		}else{
			$order['storetitle']='平台自营';
		}
		$wxappmsg=array(
			array('value'=>$order['storetitle']),
			array('value'=>$order['price']),
			array('value'=>$order['api_data']['usernum']),
			array('value'=>$order['statustitle']),
			array('value'=>$order['goods']['0']['title'].'等商品'),
		);
		if($_SESSION['wxapp_id'] && $wxapptemplate_id){
			$url='/jy_merch/member/index/index';
			$template_id=cfc('wxapp_api',$wxapp_id)->checktplNotice($order['mid'],$wxapptemplate_id,$wxappmsg,$url,'pay2buyer','jy_merch',$order['id']);
		}
	}
	public function notice_change($order=array()){
		//账户余额通知
		$paylog=pdo_get('core_paylog',array('id'=>$order['pay_id'],'uniacid'=>$_SESSION['uniacid']));
		if($paylog['di_fee']<=0 || $paylog['di_credit']!='credit2'){
			return false;
		}
		$item=model('core/member')->detail($order['mid'],array('credit1','credit2','credit3','credit4','credit5','credit6','mobile','avatar','nickname'));
		$wxapp_id=$order['wxapp_id'];
		if(!$_SESSION['wxapp_id'] && !$wxapp_id){
			$wxapp_id=cfc('fans')->get_appid($order['mid'],1);
		}
		if($_SESSION['wxapp_id'] || $wxapp_id){
			$wxapptemplate_id=cfc('wxapp_api')->get_tpl_template_id('1984',[9,1,5,6,8],'change','账户余额通知','jy_merch');
		}
		if($order['merchid']){
			$order['storetitle']=pdo_getcolumn('jy_merch_user',array('id'=>$order['merchid'],'uniacid'=>$_SESSION['uniacid']),'merchname');
		}else{
			$order['storetitle']='平台自营';
		}
		$wxappmsg=array(
			array('value'=>$order['storetitle']),
			array('value'=>$item['credit2']+$paylog['di_fee']),
			array('value'=>date('Y-m-d H:i:s',time())),
			array('value'=>$paylog['di_fee']),
			array('value'=>$item['credit2']),
		);
		if($_SESSION['wxapp_id'] && $wxapptemplate_id){
			$url='/jy_merch/member/index/index';
			$template_id=cfc('wxapp_api',$wxapp_id)->checktplNotice($order['mid'],$wxapptemplate_id,$wxappmsg,$url,'pay2buyer','jy_merch',$order['id']);
		}
	}
	public function notice_congzhi($recharge=array()){
		//充值结果通知
		$wxapp_id=$recharge['wxapp_id'];
		if(!$_SESSION['wxapp_id'] && !$wxapp_id){
			$wxapp_id=cfc('fans')->get_appid($recharge['mid'],1);
		}
		if($_SESSION['wxapp_id'] || $wxapp_id){
			$wxapptemplate_id=cfc('wxapp_api')->get_tpl_template_id('27464',[1,2,3,4,5],'congzhi','充值结果通知','jy_merch');
		}
		$wxappmsg=array(
			array('value'=>'SN'.$recharge['id']),
			array('value'=>date('Y-m-d H:i:s',time())),
			array('value'=>$recharge['fee']),
			array('value'=>$recharge['songfee']),
			array('value'=>$recharge['fee']+$recharge['songfee']),
		);
		if($_SESSION['wxapp_id'] && $wxapptemplate_id){
			$url='/jy_merch/member/index/index';
			$template_id=cfc('wxapp_api',$wxapp_id)->checktplNotice($recharge['mid'],$wxapptemplate_id,$wxappmsg,$url,'congzhi','jy_merch',$recharge['id']);
		}
	}
	
	public function notice_brith($brith=array()){
		//生日祝福提醒
		$wxapp_id=$brith['wxapp_id'];
		if(!$_SESSION['wxapp_id'] && !$wxapp_id){
			$wxapp_id=cfc('fans')->get_appid($brith['mid'],1);
		}
		if($_SESSION['wxapp_id'] || $wxapp_id){
	                                 
			$wxapptemplate_id=cfc('wxapp_api')->get_tpl_template_id('44331',[1,2,3,4],'birth','生日祝福提醒','jy_merch');
		}
		$wxappmsg=array(
			array('value'=>$brith['realname']), //姓名
			array('value'=>$brith['ctime']), //时间   2023年03月08日
			array('value'=>'快乐的光芒永远萦绕你身旁、祝生日欢乐！'), //祝福语
			array('value'=>$brith['liwu']), //礼物
		);
		if($_SESSION['wxapp_id'] && $wxapptemplate_id){
			$url='/jy_merch/member/index/index';
			$template_id=cfc('wxapp_api',$wxapp_id)->checktplNotice($brith['mid'],$wxapptemplate_id,$wxappmsg,$url,'brith','jy_merch',$brith['id']);
		}
	}
	
	//优惠券即将到期提醒
	public function notice_dqcoupon($coupon=array()){
	    
	    $wxapp_id=$coupon['wxapp_id'];
		if(!$_SESSION['wxapp_id'] && !$wxapp_id){
			$wxapp_id=cfc('fans')->get_appid($coupon['mid'],1);
		}
		if($_SESSION['wxapp_id'] || $wxapp_id){
			$wxapptemplate_id=cfc('wxapp_api')->get_tpl_template_id('49640',[1,2,3,4],'dqcoupon','优惠券即将到期提醒','jy_merch');
		}
		$wxappmsg=array(
			array('value'=>$coupon['title']),
			array('value'=>$coupon['price']),
			array('value'=>date('Y-m-d H:i:s',$coupon['dqtime'])),
			array('value'=>$coupon['merchname']),
		);
		if($_SESSION['wxapp_id'] && $wxapptemplate_id){
			$url='/jy_merch/member/index/index';
			$template_id=cfc('wxapp_api',$wxapp_id)->checktplNotice($coupon['mid'],$wxapptemplate_id,$wxappmsg,$url,'dqcoupon','jy_merch',$coupon['id']);
		}
	}
	
	//优惠券到账通知
	public function notice_dzcoupon($coupon=array()){
	    
	    $wxapp_id=$recharge['wxapp_id'];
		if(!$_SESSION['wxapp_id'] && !$wxapp_id){
			$wxapp_id=cfc('fans')->get_appid($recharge['mid'],1);
		}
		if($_SESSION['wxapp_id'] || $wxapp_id){
			$wxapptemplate_id=cfc('wxapp_api')->get_tpl_template_id('35936',[1,2,3,5,6],'dzcoupon','优惠券到账通知','jy_merch');
		}
		$wxappmsg=array(
			array('value'=>$coupon['merchname']),
			array('value'=>$coupon['title']),
			array('value'=>$coupon['day']),
			array('value'=>$coupon['type']), //优惠劵  减免劵 抵扣劵
			array('value'=>date('Y-m-d H:i:s',$coupon['jztime'])),
		);
		if($_SESSION['wxapp_id'] && $wxapptemplate_id){
			$url='/jy_merch/member/index/index';
			$template_id=cfc('wxapp_api',$wxapp_id)->checktplNotice($coupon['mid'],$wxapptemplate_id,$wxappmsg,$url,'dzcoupon','jy_merch',$coupon['id']);
		}
	}
}